package com.miyake.dsp.osa.lab.wrapper;

import com.miyake.dsp.ComplexArray;
import com.miyake.dsp.ScilabExecute;
import com.miyake.dsp.common.CommonTool;
import com.miyake.dsp.osa.lab.Calculator;
import com.miyake.dsp.osa.lab.HistogramSetting;
import com.miyake.dsp.osa.lab.LabUiAnnotation;
@LabUiAnnotation(caption="Histogram")
public class HistogramWrapper extends Calculator {
	public static final String INPUT = "Input";
	public static final String OUTPUTY = "Output Y";
	public static final String OUTPUTX = "Output X";
	private HistogramSetting setting;
	
	public HistogramWrapper(HistogramSetting setting) {
		initInput(INPUT);
		initOutput(OUTPUTX);
		initOutput(OUTPUTY);
		this.setting = setting;
	}
	
	@Override
	public synchronized void process() {
		double[] in = getInput(INPUT).getRealPart();
		double max = CommonTool.getMaxValue(in);
		double min = CommonTool.getMinValue(in);
		double step = (max - min) / (double)setting.getDivisions();
		double[] x = new double[setting.getDivisions()];
		for (int i = 0; i < setting.getDivisions(); i++) {
			x[i] = min + step * (double)i;
		}
		
		String command = "[ind, ret] = dsearch(data1, data2);";
		ComplexArray ret = ScilabExecute.execute(command, getInput(INPUT), new ComplexArray(x), "ret");
		this.setOutput(OUTPUTX, x);
		this.setOutput(OUTPUTY, ret);
	}

	@Override
	public Object getSetting() {
		return this.setting;
	}

}
